Jetfire Code: QnA

Modified on 2010/01/19 21:57 by John — Categorized as: Jetfire Code

Table of Contents [Hide/Show]


Jetfire Code: QnA Class

The Jetfire Code Class for QnA (Questions and Answers) is shown below in the box. This simple class is inherited by Quizes and Surveys that are designed using Form Maker.

// Q n A    W O R K F L O W
//===================================================================================
// QnA.txt
//===================================================================================
// Copyright (C) 2008 TrackerRealm Corporation
// This file is part of Jetfire.  http://Jetfire.ca
// 
// Jetfire is open software: you can redistribute it and/or modify it under the terms of the 
// GNU General Public License as published by the Free Software Foundation, version 3 of the License.
// 
// Jetfire is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
// See the GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License along with Jetfire.  
// If not, see http://www.gnu.org/licenses.
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT.
//===================================================================================

namespace JetfireBase
{
	// This workflow provides a Base Class for associating Questions and Answers.
	public workflow QnA
	{
		// Need to add default Constructor.
		private QnA()
		{
			this.Subject = "What is your name?";
			this.inputType = QnAInput.Text;
			this.Answers.Add("Bob");
		}
		// Define a question where the user enters one or more yes/no, decimal, integer, selection or text answers
		// Selection is a list from which the user may select an answer
		public QnA(string question, int numberOfAnswers, QnAInput inputType)
		{
			string s = "";
			this.Subject = question;
			this.inputType = inputType;
			if (inputType == QnAInput.YesNo)
			{	// Pre-populate the list for the display
				this.Answers.Add(false);
				return;
			}
			if (inputType == QnAInput.Decimal)
			{	// Pre-populate the list for the display
				this.Answers.Add(0);
				return;
			}
			if (inputType == QnAInput.Integer)
			{	// Pre-populate the list for the display
				this.Answers.Add(0);
				return;
			}
			if (inputType == QnAInput.Number)
			{	// Pre-populate the list for the display
				this.Answers.Add(0);
				return;
			}
			if (inputType == QnAInput.Text)
			{	// Pre-populate the list for the display
				this.Answers.Add(s);
				return;
			}
			if (inputType == QnAInput.Text_Long)
			{	// Pre-populate the list for the display
				this.Answers.Add(s);
				return;
			}
			if (inputType == QnAInput.DateTime)
			{	// Pre-populate the list for the display
				this.Answers.Add(DateTime.Today);
				return;
			}
			if (inputType == QnAInput.Date)
			{	// Pre-populate the list for the display
				this.Answers.Add(Date.Today);
				return;
			}
			if (inputType == QnAInput.Duration)
			{	// Pre-populate the list for the display
				this.Answers.Add(TimeSpan.Zero);
				return;
			}
			if (inputType == QnAInput.Selection)
			{	// Pre-populate the list for the display
				for (int i=0; i < numberOfAnswers; i=i+1)
				{
					this.Answers.Add(s);
				}
				return;
			}
			if (inputType == QnAInput.MultiSelect)
			{	// Pre-populate the list for the display
				for (int i=0; i < numberOfAnswers; i=i+1)
				{
					this.Answers.Add(s);
				}
				return;
			}
			if (inputType == QnAInput.List)
			{	// Pre-populate the list for the display
				for (int i=0; i < numberOfAnswers; i=i+1)
				{
					this.Answers.Add(s);
				}
				return;
			}
		}
		// Define a question where the user enters one text answer
		public QnA(string question, string answer)
		{
			this.Subject = question;
			this.inputType = QnAInput.Text;
			this.answers.Add(answer);
		}
		// Define a question where the user enters one decimal answer
		public QnA(string question, decimal answer)
		{
			this.Subject = question;
			this.inputType = QnAInput.Decimal;
			this.answers.Add(answer);
		}
		// Define a question where the user enters one integer answer
		public QnA(string question, int answer)
		{
			this.Subject = question;
			this.inputType = QnAInput.Integer;
			this.answers.Add(answer);
		}
		// Define a question where the user enters one yes/no answer
		public QnA(string question, bool answer)
		{
			this.Subject = question;
			this.inputType = QnAInput.YesNo;
			this.answers.Add(answer);
		}
		// Define a question where the user enters a Date/Time
		public QnA(string question, DateTime answer)
		{
			this.Subject = question;
			this.inputType = QnAInput.DateTime;
			this.answers.Add(answer);
		}
		// Define a question where the user enters a Date
		public QnA(string question, Date answer)
		{
			this.Subject = question;
			this.inputType = QnAInput.Date;
			this.answers.Add(answer);
		}
		// Define a question where the user enters a Duration (time span)
		public QnA(string question, TimeSpan answer)
		{
			this.Subject = question;
			this.inputType = QnAInput.Duration;
			this.answers.Add(answer);
		}
		// Define a question where the user enters a list of answers
		public QnA(string question, List answers, QnAInput inputType)
		{
			this.Subject = question;
			this.inputType = inputType;
			this.answers = answers;
		}

		// PROPERTIES
		string question;
		QnAInput inputType = QnAInput.Text;
		string selectedAnswer = "";
		List answers = new List();

		public string Question
		{
			get { return this.Subject;	}
			set { this.Subject = value;	}
		}
		public QnAInput InputType
		{
			get { return this.inputType; }
		}
		public string SelectedAnswer
		{
			get { return this.selectedAnswer;	}
			set { this.selectedAnswer = value;	}
		}
		public List Answers
		{
			get { return this.answers;		}
		}
	}
	// Enumeration for the type of Answer expected
	public enum QnAInput
	{
		// User inputs text
		Text,
		// User inputs text in a BIG textbox
		Text_Long,
		// Left in for historical reasons - USE INT OR DECIMAL
		Number,
		// User inputs a number (integer)	
		Integer,
		// User inputs a number (decimal)		
		Decimal,
		// User checks a checkbox
		YesNo,
		// User selects a date and time
		DateTime,
		// User selects a date
		Date,
		// User selects a time span
		Duration,
		// Simple Collection
		List,
		// User selects from an enumerated list
		Selection,
		// User may select one or more items from a list
		MultiSelect
	}
}

See Also

Jetfire Code Library
Jetfire Code Base Library